﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JR.Trc.MessageCenter.Lib.Impls
{
    public class RbMqMessageSender : IMessageSender
    {
        private RbmqParameters paras = null;
        public RbMqMessageSender(RbmqParameters paras)
        {
            this.paras = paras;
        }
        public void SendMsg()
        {
            if (this.paras != null)
            {
                if (string.IsNullOrWhiteSpace(this.paras.ExchangeName))
                {
                    throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.ExchangeName)));
                }
                if (string.IsNullOrWhiteSpace(this.paras.ExchangeType))
                {
                    throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.ExchangeType)));
                }
                if (this.paras.Message.GetType() != typeof(string) && this.paras.Message == null)
                {
                    throw new ArgumentNullException(string.Format("参数{0}无效!", nameof(this.paras.Message)));
                }
                RabbitMQHelper.Enqueue(paras.ExchangeName, paras.ExchangeType, paras.RoutingKey, paras.Message);
            }
        }
    }
}
